import { useState } from "react";
import "./index.less";
import { Input, message } from "antd";
import { request } from "../../../../../common/request";
import { urls } from "../../../../../common/urls";
import UploadImg from "../../../../../components/UploadImg";

const { TextArea } = Input;

function Suggestion() {
  const [content, setContent] = useState('');
  const [imageList, setImageList] = useState('');

  const handleSetImageList = (img: string) => {
    setImageList(img);
  }

  const handleSetContent = (e: any) => {
    setContent(e.target.value);
  }

  const submitAuthentication = () => {
    request({
      method: "post",
      data: {
        method: urls.submitSuggset,
        content: content,
        image: imageList
      },
    }).then((res: any) => {
      message.success(res.msg);
    }).catch((err) => {
      message.error(err);
    });
  };


  return (
    <>
      <div className="suggestion-page text-style">
        <div className="suggestion-page-problem">
          <div className="suggestion-page-title">问题描述</div>
          <TextArea
            className="suggestion-page-textArea"
            style={{ height: 160, resize: 'none' }}
            placeholder="请填写问题描述"
            value={ content }
            onChange={ handleSetContent }
          />
        </div>
        <div className="suggestion-page-picture">
          <div className="suggestion-page-title">问题截图</div>
          <UploadImg className="suggestion-page-icon" groupImg="/assets/icon/txl_qun_yaoqing@2x.png" getAvatar={ handleSetImageList } />
        </div>
        <div className="suggestion-page-btn" onClick={ submitAuthentication }>提交</div>
      </div>
    </>
  );
}

export default Suggestion;
